package com.hxs.learn.action.core;

import com.hxs.learn.common.web.LoginInfo;
import com.hxs.learn.common.web.annotation.Login;
import com.hxs.learn.constants.core.web.ReqConst;
import com.hxs.learn.constants.core.web.view.ViewNames;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 装饰页面
 *
 * @author King
 * @since 2017/11/2
 */
@RestController
public class DecoratorController extends AbstractViewAction {
    @Value("${learn.admin.authenticate.login:login}")
    private String loginPage;
    @Value("${learn.admin.authenticate.decorator:_include/decorator}")
    private String decoratorPage;

    @RequestMapping(ReqConst.REQ_DECORATOR)
    @ResponseBody
    public ModelAndView decorator() {
        return createModelAndView(decoratorPage);
    }

    @GetMapping(ReqConst.REQ_INDEX)
    @ResponseBody
    public ModelAndView index(@Login LoginInfo user, ModelMap model) {
        model.addAttribute(CURR_USER, user);

        return new ModelAndView(ViewNames.PAGE_INDEX);
    }

    @GetMapping(ReqConst.REQ_LOGIN)
    @ResponseBody
    public ModelAndView login() {
        return new ModelAndView(loginPage);
    }

    @GetMapping(value = ReqConst.REQ_LOGOUT)
    public void logout() {
        SecurityUtils.getSubject().logout();
    }

    @GetMapping(ReqConst.REQ_MAIN)
    @ResponseBody
    public ModelAndView main() {
        return createModelAndView(ViewNames.PAGE_MAIN);
    }

    @GetMapping(ReqConst.REQ_THEME)
    @ResponseBody
    public ModelAndView theme() {
        return createModelAndView(ViewNames.PAGE_THEME);
    }

    @GetMapping(ReqConst.REQ_FORGET)
    @ResponseBody
    public ModelAndView forget(ModelMap model) {
        return new ModelAndView(ViewNames.PAGE_FORGET);
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
